package logic

import (
	"context"
	"ykone/models/redis"
	"ykone/ykonerpc/internal/svc"
	"ykone/ykonerpc/ykonerpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type ProduceCollectListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewProduceCollectListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ProduceCollectListLogic {
	return &ProduceCollectListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *ProduceCollectListLogic) ProduceCollectList(in *ykonerpc.ProduceCollectListRequest) (*ykonerpc.ProduceCollectListResponse, error) {
	// todo: add your logic here and delete this line

	scores := redis.Client.ZRevRangeWithScores("collectlist", 0, -1)

	var Listslice []*ykonerpc.ProduceListStruct
	for _, list := range scores.Val() {

		ProduceCollect := &ykonerpc.ProduceListStruct{
			ProductName: list.Member.(string),
			Score:       int64(list.Score),
		}
		Listslice = append(Listslice, ProduceCollect)
	}

	return &ykonerpc.ProduceCollectListResponse{Lists: Listslice}, nil
}
